package com.dykj.fireFighting.web.app;

import com.dykj.fireFighting.api.base.enterprise.entity.Enterprise;
import com.dykj.fireFighting.api.base.enterprise.service.IEnterpriseService;
import com.dykj.fireFighting.api.base.maintenanceplan.dto.MaintenancePlanDto;
import com.dykj.fireFighting.api.base.maintenanceplan.entity.MaintenancePlan;
import com.dykj.fireFighting.api.base.maintenanceplan.service.IMaintenancePlanService;
import com.dykj.fireFighting.api.base.maintenanceplan.vo.MaintenancePlanVo;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.vo.LoginUserVo;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: zly
 * @Description :
 * @Date: 2021-07-30
 */
@Slf4j
@Api(value = "社会端维保计划接口", tags = {"社会端维保计划接口"})
@RestController
@RequestMapping("app/maintenancePlan")
public class AppMaintenancePlanController {

    @DubboReference
    private IMaintenancePlanService maintenancePlanService;

    @DubboReference
    private IEnterpriseService enterpriseService;
    /**
     * 列表
     *
     * @return
     */
    @AutoLog(value = "-分页列表查询")
    @ApiOperation(value = "分页列表", notes = "分页列表")
    @GetMapping("/list")
    public CommonResult<PageVo<MaintenancePlan>> treeGrid(MaintenancePlanDto maintenancePlanDto) {

        maintenancePlanDto.setSocialUnitId(ShiroUtil.getUser().getEnterpriseId().toString());
        PageVo<MaintenancePlan> page = maintenancePlanService.queryList(maintenancePlanDto);
        return CommonResult.success(page);
    }

    /**
     * 列表
     *
     * @return
     */
    @AutoLog(value = "-分页预警列表查询")
    @ApiOperation(value = "分页预警列表", notes = "分页预警列表")
    @GetMapping("/warnList")
    //@RequiresPermissions("maintenanceplan/maintenancePlan/list")
    public CommonResult<PageVo<MaintenancePlanVo>> warnList(MaintenancePlanDto maintenancePlanDto) {
        LoginUserVo loginUserVo = ShiroUtil.getUser();
        if(loginUserVo.getUserType()!=0)
        {
            maintenancePlanDto.setSocialUnitId(loginUserVo.getEnterpriseId().toString());
        }
        PageVo<MaintenancePlanVo> page = maintenancePlanService.queryWarnList(maintenancePlanDto);
        return CommonResult.success(page);
    }

    /**
     *根据合同返回社会单位
     *
     */
    @AutoLog(value = "返回合同中社会单位")
    @ApiOperation(value = "返回合同中社会单位", notes = "返回合同中社会单位")
    @GetMapping("/querySocialUnits")
    public CommonResult querySocialUnits(){

        HashMap<String, Object> params = new HashMap<>(16);
        params.put("weibaoUnit",ShiroUtil.getUser().getEnterpriseId().toString());
        List<Enterprise> list=enterpriseService.querySocialUnits(params);
        return CommonResult.success(list);
    }
}
